package com.yanqu.road.server.cmd.activity.zhenhuan.cross.thirdProcess;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityCivilRewardModule;
import com.yanqu.road.server.protocol.Protocol;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Cmd(code = Protocol.S_ZHENHUAN_THIRD_PROCESS_SELF_DATA_SYNC_FROM_CROSS, desc = "跨服同步个人活动信息回包")
public class ZhenHuanThirdProcessSelfDataSyncFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ZhenHuanProto.ZhenHuanThirdProcessSelfDataSyncMsg msg = ZhenHuanProto.ZhenHuanThirdProcessSelfDataSyncMsg.parseFrom(packet.getBytes());
        Map<Long, Long> activityUserIdMap = new HashMap<>();
        //获取是否有全民奖励可领取
        for (ZhenHuanProto.ZhenHuanThirdProcessSimpleUserTempMsg userData : msg.getUserDataList()) {
            activityUserIdMap.put(userData.getUserId(), (long) userData.getBanquetCount());
        }
        boolean canReceiveFlag = player.getModule(ActivityCivilRewardModule.class).checkCanReceiveCivilReward(msg.getActivityId(),
                eGamePlayerEventType.ZhenHuanThirdProcessBanquetTimesCivil.getValue(), activityUserIdMap);
        ZhenHuanProto.ZhenHuanThirdProcessSelfDataSyncMsg.Builder builder = msg.toBuilder();
        builder.setCivilRewardFlag(canReceiveFlag);
        builder.clearUserData();
        //返回
        player.sendPacket(Protocol.U_ZHENHUAN_THIRD_PROCESS_SELF_DATA_SYNC, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
